<?php namespace Phpcmf\Controllers;

/**
 * 二次开发时可以修改本文件，不影响升级覆盖
 */

class Pinglun extends \Phpcmf\Home\Module
{

	public function  pinglun_panduan() {
		//get 参数
		if(!$this->uid){
			$id = (int)\Phpcmf\Service::L('input')->get('id'); //帖子id
		
			$pinglun_tongji = \Phpcmf\Service::M()->db->table('1_quan_form_quantie_dianzan')->where('tieid', $id)->countAllResults();
			$data = [
				'code' => 0,
				'data' => $pinglun_tongji,
				'uid'=> 0,
			];
			$this->_json('1', '未登录',$data);									
		} else {
			$id = (int)\Phpcmf\Service::L('input')->get('id'); //帖子id
		
			$pinglun_data = \Phpcmf\Service::M()->db->table('1_quan_form_quantie_dianzan')->where('tieid', $id)->where('uid', $this->uid)->countAllResults();
			$pinglun_tongji = \Phpcmf\Service::M()->db->table('1_quan_form_quantie_dianzan')->where('tieid', $id)->countAllResults();
			if($pinglun_data){
				$data = [
					'code' => 1,
					'data' => $pinglun_tongji,
					'uid'=> $this->uid,
	
				];
	
				$this->_json('1', '已点赞',$data);
			} else {
				$data = [
					'code' => 2,
					'data' => $pinglun_tongji,
					'uid'=> $this->uid,
	
				];

				$this->_json('0', '未点赞',$data);
			}
		}
		
		
	}
	// 头像
	public function  pinglun_touxiang() {
		$id = (int)\Phpcmf\Service::L('input')->get('id'); //帖子id
		
		$shuju_data = \Phpcmf\Service::M()->table('1_quan_form_quantie_pinglun')->getAll();
		// 循环头像
		$touxiang = [];
		if($shuju_data){
			foreach ($shuju_data as $key => $value) {
				$touxiang[] = dr_avatar($shuju_data['uid']);
			}
		}

		$this->_json('0', '点赞头像',$touxiang);
		
	}
	// 评论
	public function  pinglun_index() {
		if(!$this->uid){
			$this->_json('0', '未登录');
		} else {
			if (IS_POST) {
				$jibie = (int)\Phpcmf\Service::L('input')->get('jibie'); //帖子级别
				$id = (int)\Phpcmf\Service::L('input')->get('id'); //帖子id
				$cid = (int)\Phpcmf\Service::L('input')->post('cid'); // 圈子id
				$neirong = \Phpcmf\Service::L('input')->post('neirong'); //评论内容
				$touid = (int)\Phpcmf\Service::L('input')->post('touid'); //评论贴人ID
				$ip = \Phpcmf\Service::L('Input')->ip_info();
				$shuju_data = \Phpcmf\Service::M()->table('1_quan_form_quantie')->where('id', $cid)->get();
			
				$datapinglun = [
					'uid'=> $this->uid,//评论人ID
					'touid'=> $touid, //评论贴人ID
					'quanid'=> $cid, //圈子ID
					'tieid'=> $id, //圈帖ID
					'shijian' => time(), //评论时间
					'neirong' => $neirong, //评论内容
					'shenhe' => $shuju_data['pinglunshenhe'], //评论审核
					'jibie' => $jibie, //评论级别
					'ip' => $ip,
				];
				\Phpcmf\Service::M()->table('1_quan_form_quantie_pinglun')->insert($datapinglun);
				$this->_json('1', '评论成功',$datapinglun);

			} else {
				$this->_json('0', '获取失败');

			}
		}
		
	}

}
